home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zcharx.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.4 KB  |  167 lines

  1. /* Copyright (C) 1992, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zcharx.c,v 1.3 2000/09/19 19:00:52 lpd Exp $ */
  20. /* Level 2 character operators */
  21. #include "ghost.h"
  22. #include "oper.h"
  23. #include "gsmatrix.h"        /* for gxfont.h */
  24. #include "gstext.h"
  25. #include "gxfixed.h"        /* for gxfont.h */
  26. #include "gxfont.h"
  27. #include "ialloc.h"
  28. #include "ichar.h"
  29. #include "igstate.h"
  30. #include "iname.h"
  31. #include "ibnum.h"
  32.  
  33. /* Common setup for glyphshow and .glyphwidth. */
  34. private int
  35. glyph_show_setup(i_ctx_t *i_ctx_p, gs_glyph *pglyph)
  36. {
  37.     os_ptr op = osp;
  38.  
  39.     switch (gs_currentfont(igs)->FontType) {
  40.     case ft_CID_encrypted:
  41.     case ft_CID_user_defined:
  42.     case ft_CID_TrueType:
  43.     case ft_CID_bitmap:
  44.         check_int_leu(*op, gs_max_glyph - gs_min_cid_glyph);
  45.         *pglyph = (gs_glyph) op->value.intval + gs_min_cid_glyph;
  46.         break;
  47.     default:
  48.         check_type(*op, t_name);
  49.         *pglyph = name_index(op);
  50.     }
  51.     return op_show_enum_setup(i_ctx_p);
  52. }
  53.  
  54. /* <charname> glyphshow - */
  55. private int
  56. zglyphshow(i_ctx_t *i_ctx_p)
  57. {
  58.     gs_glyph glyph;
  59.     gs_text_enum_t *penum;
  60.     int code;
  61.  
  62.     if ((code = glyph_show_setup(i_ctx_p, &glyph)) != 0 ||
  63.     (code = gs_glyphshow_begin(igs, glyph, imemory, &penum)) < 0)
  64.     return code;
  65.     if ((code = op_show_finish_setup(i_ctx_p, penum, 1, NULL)) < 0) {
  66.     ifree_object(penum, "zglyphshow");
  67.     return code;
  68.     }
  69.     return op_show_continue_pop(i_ctx_p, 1);
  70. }
  71.  
  72. /* <charname> .glyphwidth <wx> <wy> */
  73. private int
  74. zglyphwidth(i_ctx_t *i_ctx_p)
  75. {
  76.     gs_glyph glyph;
  77.     gs_text_enum_t *penum;
  78.     int code;
  79.  
  80.     if ((code = glyph_show_setup(i_ctx_p, &glyph)) != 0 ||
  81.     (code = gs_glyphwidth_begin(igs, glyph, imemory, &penum)) < 0)
  82.     return code;
  83.     if ((code = op_show_finish_setup(i_ctx_p, penum, 1, finish_stringwidth)) < 0) {
  84.     ifree_object(penum, "zglyphwidth");
  85.     return code;
  86.     }
  87.     return op_show_continue_pop(i_ctx_p, 1);
  88. }
  89.  
  90. /* <string> <numarray|numstring> xshow - */
  91. /* <string> <numarray|numstring> yshow - */
  92. /* <string> <numarray|numstring> xyshow - */
  93. private int
  94. moveshow(i_ctx_t *i_ctx_p, bool have_x, bool have_y)
  95. {
  96.     os_ptr op = osp;
  97.     gs_text_enum_t *penum;
  98.     int code = op_show_setup(i_ctx_p, op - 1);
  99.     int format;
  100.     uint i, size;
  101.     float *values;
  102.  
  103.     if (code != 0)
  104.     return code;
  105.     format = num_array_format(op);
  106.     if (format < 0)
  107.     return format;
  108.     size = num_array_size(op, format);
  109.     values = (float *)ialloc_byte_array(size, sizeof(float), "moveshow");
  110.     if (values == 0)
  111.     return_error(e_VMerror);
  112.     for (i = 0; i < size; ++i) {
  113.     ref value;
  114.  
  115.     switch (code = num_array_get(op, format, i, &value)) {
  116.     case t_integer:
  117.         values[i] = value.value.intval; break;
  118.     case t_real:
  119.         values[i] = value.value.realval; break;
  120.     case t_null:
  121.         code = gs_note_error(e_rangecheck);
  122.         /* falls through */
  123.     default:
  124.         ifree_object(values, "moveshow");
  125.         return code;
  126.     }
  127.     }
  128.     if ((code = gs_xyshow_begin(igs, op[-1].value.bytes, r_size(op - 1),
  129.                 (have_x ? values : (float *)0),
  130.                 (have_y ? values : (float *)0),
  131.                 size, imemory, &penum)) < 0 ||
  132.     (code = op_show_finish_setup(i_ctx_p, penum, 2, NULL)) < 0) {
  133.     ifree_object(values, "moveshow");
  134.     return code;
  135.     }
  136.     pop(2);
  137.     return op_show_continue(i_ctx_p);
  138. }
  139. private int
  140. zxshow(i_ctx_t *i_ctx_p)
  141. {
  142.     return moveshow(i_ctx_p, true, false);
  143. }
  144. private int
  145. zyshow(i_ctx_t *i_ctx_p)
  146. {
  147.     return moveshow(i_ctx_p, false, true);
  148. }
  149. private int
  150. zxyshow(i_ctx_t *i_ctx_p)
  151. {
  152.     return moveshow(i_ctx_p, true, true);
  153. }
  154.  
  155. /* ------ Initialization procedure ------ */
  156.  
  157. const op_def zcharx_op_defs[] =
  158. {
  159.     op_def_begin_level2(),
  160.     {"1glyphshow", zglyphshow},
  161.     {"1.glyphwidth", zglyphwidth},
  162.     {"2xshow", zxshow},
  163.     {"2xyshow", zxyshow},
  164.     {"2yshow", zyshow},
  165.     op_def_end(0)
  166. };
  167.